package com.lemon.blog.web.controller;

import com.lemon.blog.web.domain.BlBlog;
import com.lemon.blog.web.service.IBlBlogService;
import com.lemon.blog.web.vo.KeyWordVO;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.web.page.TableDataInfo;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * 包名称：com.lemon.admin.web.controller.blog
 * 类名称：BlBlogController
 * 类描述：博客controller
 * 创建人：@author huangpeng
 * 创建时间：2022年04月10日 01:01
 */
@Api("博客信息")
@RestController
@RequestMapping("/blog")
public class BlBlogController extends BaseController {

    @Autowired
    private IBlBlogService blBlogService;

    /**
     * 查询博客管理列表
     * @Title: list
     * @Description: 查询博客管理列表
     * @param blBlog
     * @return: TableDataInfo
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:34
     */
    @GetMapping("/list")
    public TableDataInfo list(BlBlog blBlog) {
        startPage();
        List<BlBlog> list = blBlogService.selectBlBlogList(blBlog);
        return getDataTable(list);
    }

    /**
     * 获取博客管理详细信息
     * @Title: getInfo
     * @Description: 获取博客管理详细信息
     * @param id 博客id
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:34
     */
    @GetMapping(value = "/info")
    public AjaxResult getInfo(@RequestParam("id") Long id) {
        return AjaxResult.success(blBlogService.selectByPrimaryKey(id));
    }

    /**
     * 新增博客
     * @Title: add
     * @Description: 新增博客
     * @param blBlog
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:35
     */
    @Log(title = "博客管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlBlog blBlog) {
        return toAjax(blBlogService.insert(blBlog));
    }

    /**
     * 修改博客
     * @Title: edit
     * @Description: 修改博客
     * @param blBlog
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:35
     */
    @Log(title = "博客管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlBlog blBlog) {
        return toAjax(blBlogService.update(blBlog));
    }

    /**
     * 删除博客
     * @Title: remove
     * @Description: 删除博客
     * @param ids 博客id，多个逗号隔开
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:36
     */
    @Log(title = "博客管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids) {
        return toAjax(blBlogService.deleteByBatch(ids));
    }

    /**
     * 查询博客管理列表
     * @Title: queryRecommendList
     * @Description: 查询博客管理列表
     * @return: TableDataInfo
     * @throws:
     * @author: huangpeng
     * @Date: 2023/8/1 16:48
     */
    @GetMapping("/queryRecommendList")
    public AjaxResult queryRecommendList() {
        List<BlBlog> list = blBlogService.queryRecommendList();
        return AjaxResult.success(list);
    }


    /**
     * 阅读文章
     * @Title: read
     * @Description: 阅读文章
     * @param blBlog
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/8/21 23:35
     */
    @Log(title = "博客管理阅读", businessType = BusinessType.UPDATE)
    @PutMapping("/read")
    public AjaxResult read(@RequestBody BlBlog blBlog) {
        return toAjax(blBlogService.read(blBlog));
    }

    /**
     * 获取时间数据
     * @Title: queryTimeData
     * @Description: 获取时间数据
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/9/3 20:25
     */
    @GetMapping("/queryTimeList")
    public AjaxResult queryTimeData() {
        return AjaxResult.success(blBlogService.queryTimeList());
    }

    /**
     * 保存搜索记录
     * @Title: saveSearchKeyWord
     * @Description: 保存搜索记录
     * @param map
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/9/4 19:52
     */
    @Log(title = "博客管理保存搜索记录", businessType = BusinessType.INSERT)
    @PostMapping("/saveSearchKeyWord")
    public AjaxResult saveSearchKeyWord(@RequestBody Map<String, Object> map) {
        blBlogService.saveSearchKeyWord(map);
        return AjaxResult.success();
    }

    /**
     * 获取搜索记录列表
     * @Title: queryKeyWordList
     * @Description: 获取搜索记录列表
     * @param
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/9/4 20:43
     */
    @GetMapping("/queryKeyWordList")
    public AjaxResult queryKeyWordList() {
        return AjaxResult.success(blBlogService.queryKeyWordList());
    }

    /**
     * 文章提交复核
     * @Title: submitApproval
     * @Description: 文章提交复核
     * @param blBlog
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/9/8 11:21
     */
    @Log(title = "文章提交复核", businessType = BusinessType.UPDATE)
    @PutMapping("/submitApproval")
    public AjaxResult submitApproval(@RequestBody BlBlog blBlog) {
        return AjaxResult.success(blBlogService.submitApproval(blBlog));
    }



}
